	var start = 0;
	var pageSize = 12;
	
	var selectState = 1;
	var selectDetailState = 1;
	var goodState = 0;
	
	var imgId = "imgId0";

	$(document).ready(function() 
	{
		getImgViews();
		
		$("#getMoreImgViews").click(function()
		{
			if(selectState == 1)
			{
				selectState = 0;
				
				$("#getMoreImgViews").text("正在查询，请稍等");
				
				getImgViews();
			}
		});
		
		$(".imgViewDetilClick").live('click',function()
		{
			if(selectDetailState == 1)
			{
				selectDetailState = 0;
				
				$("#imgViewDetail").animate({"top":$(document).scrollTop() + "px"});
				$("#imgViewDetail").show(500);
				
				imgId = $(this).attr("id");
				getImgView(imgId.substr(5));
			}
		});
		
		$("#imgViewDetailClose").click(function(){
			$("#imgViewDetail").hide(500);
		});
		
		$("#imgViewDetailGood").click(function(){
			good();
		});
	});
	
	function getImgViews()
	{
		jQuery.ajax({
		type: 'POST',        
		url: "/student/imgViewFind.do",
		cache: false,
		data:"start=" + start + "&end=" + (start + pageSize - 1) + "&kind=time",
		dataType:"json",
		success: function(data){
			start += pageSize;
			
			var imgs = data.imgs;
			
			if(imgs.length == 13)
			{
				selectState = 1;
				$("#getMoreImgViews").text("查看更多");
			}
			else
			{
				selectState = 2;
				$("#getMoreImgViews").text("就这些啦~");
			}
			
			for(var i=1; i<imgs.length; i++)
			{
				var colum = "#colum" + (i-1) % 4;
				
				var innerShow = "<div class=\"b-line b-line1\"></div><div class=\"b-line b-line2\"></div><div class=\"b-line b-line3\"></div><div class=\"b-line b-line4\"></div><div class=\"b-line b-line5\"></div>";
				
				var inner = "<li><div id=\"imgId" + imgs[i].id + "\" class=\"imgViewDetilClick\"><div class=\"b-link-stripe b-animate-go  thickbox\" >" + innerShow;
				inner = inner + "<img src=\"" + imgs[i].url + "\" width=\"300px\" /><div class=\"b-wrapper\"><h2 class=\"b-animate b-from-left    b-delay03 \"></h2>";
				inner += "<p class=\"b-animate b-from-right    b-delay03 \"> <!-- " + imgs[i].studentid + "<br> --> <span class=\"m_4\">" + imgs[i].message + "</span></p></div>";
				inner += "<span id=\"imgViewGood" + imgs[i].id + "\" style=\"position:absolute; bottom:5px; right:5px; color:#CCC;\">" + imgs[i].goodnum + "赞</span></div></div></li>";
				
				$(colum).append(inner);
			}
		},
		 error: function(XMLHttpRequest, textStatus, errorThrown) {
			 selectState = 1;
			 $("#getMoreImgViews").text("查询失败，错误代码" + XMLHttpRequest.status);
			},
		});
	}
	
	function getImgView(id)
	{
		jQuery.ajax({
		type: 'POST',        
		url: "/student/imgViewDetail.do",
		cache: false,
		data:"id=" + id,
		dataType:"json",
		success: function(data){
			selectDetailState = 1;
			$("#imgViewDetailLeft").html("<img src=\"" + data.imgs.url + "\" width=\"600px\" />");
			$("#imgViewDetailStudentId").text(data.imgs.publishStudentId);
			$("#imgViewDetailMessage").text(data.imgs.message);
			$("#imgViewDetailGoodNum").text(data.imgs.goodnum);
			if(data.imgs.state == 1000)
			{
				$("#imgViewDetailGoodState").text("赞一下");
				
				goodState = 1;
			}
			else if(data.imgs.state == 1001)
			{
				$("#imgViewDetailGoodState").text("已赞");
				
				goodState = 2;
			}
			else if(data.imgs.state == 1002)
			{
				$("#imgViewDetailGoodState").text("（登陆后可赞）");
				
				goodState = 3;
			}
		},
		 error: function(XMLHttpRequest, textStatus, errorThrown) {
			 selectState = 1;
			 $("#imgViewDetailStudentId").text("查询失败，错误代码" + XMLHttpRequest.status);
			},
		});
	}
	
	function imgViewGood(id)
	{
		jQuery.ajax({
		type: 'POST',        
		url: "/student/imgViewGood.do",
		cache: false,
		data:"imgViewId=" + id,
		dataType:"text",
		success: function(data){
			if(data.trim().localeCompare("success") == 0)
			{
				alert("成功赞了下");
				var goodnum = parseInt($("#imgViewDetailGoodNum").text());
				$("#imgViewDetailGoodNum").text(goodnum+1);
				$("#imgViewGood" + id).text((goodnum+1) + "赞");
				$("#imgViewDetailGoodState").text("已赞");
			}
			else if(data.trim().localeCompare("unlogin") == -1)
			{
				window.location.href="/login.html";
			}
			else
			{
				alert("fail");
			}
		},
		 error: function(XMLHttpRequest, textStatus, errorThrown) {
			alert(XMLHttpRequest.status + "error");
			},
		});
	}
	
	function good()
	{
		if(goodState == 1)
		{
			imgViewGood(imgId.substr(5));
		}
		else if(goodState == 2)
		{
			alert("您已经赞过啦~");
		}
		else
		{
			window.location.href="/login.html";
		}
	}